<template>
	<div>
		<CityHeader></CityHeader>
		<CitySearch :citys="citys"></CitySearch>
		<CityList 
		:citys="citys" 
		:hotCitys="hotCitys"
		:lettr="lettr"
		></CityList>
		<CityAlphabet 
		:citys="citys"
		@leletterchange="leletterchangedistribute"
		>
		</CityAlphabet>	
	</div>
</template>
<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
	name: "City",
	components: {
		CityHeader,
		CitySearch,
		CityList,
		CityAlphabet
	},
	data () {
		return {
			citys: {},
			hotCitys: [],
			lettr: ''
		}
	},
	methods: {
		gitCityInfo () {
			axios.get('/api/city.json')
			.then(this.gitCityInfoSucc)

		},
		gitCityInfoSucc (res) {
			res = res.data
			if(res.ret && res.data){
				const data = res.data
				this.citys = data.cities
				this.hotCitys = data.hotCities

			}
		},
		//监听Alphabet 组件 点击的字母
		leletterchangedistribute (handInnderText) {
			// console.log(handInnderText)
		   //当接收alphabet 的 参数时
		   console.log(handInnderText,"city==========")
			this.lettr = handInnderText
			// ===> 然后在list组件中侦听 letter 的变化

		}
	},
	mounted () {
		// 页面已经挂载 并且 整个 只执行一次  (初始化数据用)
		this.gitCityInfo()
	}

}
</script>